function save_options() {
	var samples = $("#samples");
	var value = samples.val();
	if (!value || value == "" || isNaN(value)) {
		alert("Invalid input.");
		return;
	}
	value = parseInt(value);
	if (value <= 0) {
		alert("Invalid input.");
		return;
	}
	
	localStorage["samples"] = value;

	var interval = $("#interval");
	value = interval.val();
	if (!value || value == "" || isNaN(value)) {
		alert("Invalid input.");
		return;
	}
	value = parseFloat(value);
	if (value <= .0) {
		alert("Invalid input.");
		return;
	}
	localStorage["interval"] = value;

	// Update status to let user know options were saved.
	var status = document.getElementById("status");
	status.innerHTML = "Options Saved.";
	setTimeout(function() {
		status.innerHTML = "";
	}, 750);
}

// Restores saved value from localStorage.
function restore_options() {
	var samples = localStorage["samples"];
	var interval = localStorage["interval"];
	if (!samples) {
		samples = localStorage["samples"] = 5;
	}
	$("#samples").val(samples);
	if (!interval) {
		interval = localStorage["interval"] = 500;
	}
	$("#interval").val(interval);
}

$(document).bind("DOMContentLoaded", restore_options);
$(function() {
	$("#save").bind("click", save_options);
});
